package com.supply.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.supply.pojo.Goods;
import com.supply.pojo.ResultBean;
import com.supply.req.GoodsReq;
import com.supply.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.acl.LastOwnerException;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/list")
    public ResultBean list(GoodsReq goodsReq){
        System.out.println("请求的商品信息：" + goodsReq);
        PageHelper.startPage(goodsReq.getPageNum(),goodsReq.getPageSize());
        List<Goods> goodsList = goodsService.queryByCondition(goodsReq);

        return ResultBean.success(new PageInfo(goodsList));
    }

    @GetMapping("/queryAll")
    public ResultBean queryAll(){
        return ResultBean.success(goodsService.queryAll());
    }

    @GetMapping("queryByCompanyId/{id}")
    public ResultBean queryByCompanyId(@PathVariable("id") Long id){
        return ResultBean.success(goodsService.queryByCompanyId(id));
    }

    @GetMapping("/queryById/{id}")
    public ResultBean queryById(@PathVariable("id") Long id){
        return ResultBean.success(goodsService.queryById(id));
    }
}
